var Config = require('@/utils/config.js');
let BASEURL = Config.baseUrl
export const request = (options = {}) => {
	return new Promise((resolve, rejects) => {
		handleRequest(options, resolve, rejects)
	})
}
// 发起请求
function handleRequest(options, resolve, reject) {
	const token = uni.getStorageSync('token')||""
	uni.request({
		url: BASEURL+options.url,
		method: options.method,
		header: {
			'Authorization':token?'Bearer '+token:'',
		},
		timeout:20000,
		data: options.data,
		sslVerify:false,
		success: (response) => {
			if(response.data.code==401){
				uni.showToast({
						icon:"none",
						title:"登录失效"
				})
				setTimeout(()=>{
					uni.navigateTo({
						url:"/pages/login/login"
					})
				},1000)
			}
			
			return resolve(response)
		},
		fail: (err) => {
			// console.log(err)
			return reject(err);
		}
	})
}